package cn.hengzhu.main_manager.utils.aop;


import javax.servlet.http.HttpServletRequest;

import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Before;
import org.aspectj.lang.annotation.Pointcut;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import cn.hengzhu.main_manager.utils.JudgeIsMoblie;


@Aspect
@Component
public class MAop {
	
	@Autowired
    private HttpServletRequest request;

    /**
     * Controller层切点 注解拦截 只要是有这个注解的都会被此切面切入
     */
    @Pointcut("@annotation(cn.hengzhu.main_manager.utils.ann.MoblieUrl)")
    public void controllerAspect(){}
    

    //标识次方法会在perform()方法执行之前执行
    @Before(value = "controllerAspect()") 
    public void before(JoinPoint joinPoint) {
    	boolean isMoblie = JudgeIsMoblie.judgeIsMoblie(request);
    	if(isMoblie) {
    		request.setAttribute("moblie", "moblie/M_");
    	}else {
    		request.setAttribute("moblie", "");
    	}
    }
    
}
